﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QL_Nha_Sach_Phuong_Nam
{
    public partial class FormchonsachchoPhieuDeNghi : Form
    {
        CXulythongtinsach XulySach;
        CXulyPhieuDeNghiXuatKho XulyPhieuDeNghi;

        List<ChiTietPhieuDeNghiXuatKho> dschitiet;

        public List<ChiTietPhieuDeNghiXuatKho> Dschitiet
        {
            get { return dschitiet; }
            set { dschitiet = value; }
        }

        public FormchonsachchoPhieuDeNghi()
        {
            InitializeComponent();
        }

        private void FormchonsachchoPhieuDeNghi_Load(object sender, EventArgs e)
        {
            XulySach = new CXulythongtinsach();
            XulyPhieuDeNghi = new CXulyPhieuDeNghiXuatKho();

            //load du lieu ton kho len listview
            foreach (TonKho t in XulyPhieuDeNghi.getDsTonKho())
            {
                ListViewItem lvi = lstchuachon.Items.Add(t.Sach.SachNo);
                lvi.SubItems.Add(t.Sach.SachName);
                lvi.SubItems.Add(t.SoLuong.ToString());
            }
        }

        private void btnchon_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow r in dgvluachon.Rows)
            {
                if (r.IsNewRow)
                    continue;
                ChiTietPhieuDeNghiXuatKho ctpd = new ChiTietPhieuDeNghiXuatKho();
                ctpd.FK_SachID = XulySach.TimSachtheoma(r.Cells[0].Value.ToString()).SachID;
                ctpd.Quantum = int.Parse(r.Cells[2].Value.ToString());
                dschitiet.Add(ctpd);
            }
            Close();
        }

        private void btnhuychon_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnquaphai_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem lvi in lstchuachon.SelectedItems)
            {
                int i = dgvluachon.Rows.Add();
                dgvluachon.Rows[i].Cells[0].Value = lvi.SubItems[0].Text;
                dgvluachon.Rows[i].Cells[1].Value = lvi.SubItems[1].Text;
            }
        }

        private void btnquatrai_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow r in dgvluachon.SelectedRows)
            {
                dgvluachon.Rows.Remove(r);
            }
        }
    }
}
